/**
 * <p>Title: ServiceZM97.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 高强
 * @version 1.0
 * <pre>Histroy:
 *          2012-12-13 上午10:00:31  高强  Create
 *</pre>
 */
package com.baosight.sczx.zm.service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.zm.domain.ZM97;

/**
 * 材料消耗额度统计
 * <p>Title: ServiceZM97.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 高强
 * @version 1.0
 * <pre>Histroy:
 *          2012-12-13 上午10:00:31  高强  Create
 *</pre>
 */
public class ServiceZM97 extends ServiceEPBase {
	
	/**
	 * 页面初始化方法
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *   2012-12-13 上午10:00:31  高强  Create
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) 
	{
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		return outInfo;
	}
	
	/**
	 * 查询方法
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-12-13 上午10:00:31  高强  Create
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) 
	{
		StaticTools.setQueryParameters(inInfo, "year",StaticTools.getYear(),true);//添加查询条件
		StaticTools.setQueryParameters(inInfo, "month",Integer.parseInt(StaticTools.getMonth()),true);//添加查询条件
		if(inInfo.getString("view")==null)
		{
			inInfo.addBlock(EiConstant.resultBlock).set(EiConstant.limitStr, 5);
		}else
		{
			inInfo.addBlock(EiConstant.resultBlock).set(EiConstant.limitStr, -1);
		}
		
		EiInfo outInfo = super.query(inInfo, "ZM97.query",  new ZM97());
		getEdAndTotal(outInfo);
		return outInfo;
	}
	
	/**
	 * 查询方法
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-12-13 上午10:00:31  高强  Create
	 * </p>
	 *
	 */
	public EiInfo queryAll(EiInfo inInfo) 
	{
		StaticTools.setQueryParameters(inInfo, "year",StaticTools.getYear(),true);//添加查询条件
		StaticTools.setQueryParameters(inInfo, "month",Integer.parseInt(StaticTools.getMonth()),true);//添加查询条件
		inInfo.addBlock(EiConstant.resultBlock).set(EiConstant.limitStr, -1);
		EiInfo outInfo = super.query(inInfo, "ZM97.query",  new ZM97());
		getEdAndTotal(outInfo);
		return outInfo;
	}
	
	/**
	 * 查询方法
	 * <p>Function: getEdAndTotal</p>
	 * <p>Description: </p>
	 * <p>return value: EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-12-13 上午10:00:31  高强  Create
	 * </p>
	 *
	 */
	private void getEdAndTotal(EiInfo info)
	{
		info.set("RATEDVALUE", getValue("ZM97.getRatedValue","RATEDVALUE"));
		info.set("COMSUMEVALUE", getValue("ZM97.getConsumeValue","COMSUMEVALUE"));
	}
	
	/**
	 * 查询方法
	 * <p>Function: getValue</p>
	 * <p>Description: </p>
	 * <p>return value: EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-12-13 上午10:00:31  高强  Create
	 * </p>
	 *
	 */
	private String getValue(String sql ,String column)
	{
		String value ="";
		Map<String, Object> _args = new HashMap<String, Object>();
		_args.put("month",Integer.parseInt(StaticTools.getMonth()));
		_args.put("year", StaticTools.getYear());
		
		List<Map> _result = dao.query(sql, _args);
		if(_result.size() > 0) {
			value = _result.get(0).get(column).toString();
		}
		return value;
	}
}

